

package com.oa.config;

import com.oa.modules.sys.oauth2.OAuth2Filter;
import com.oa.modules.sys.oauth2.OAuth2Realm;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Shiro配置
 *
 * @author admin
 */
@Configuration
public class ShiroConfig {

    @Bean("securityManager")
    public SecurityManager securityManager(OAuth2Realm oAuth2Realm) {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        securityManager.setRealm(oAuth2Realm);
        securityManager.setRememberMeManager(null);
        return securityManager;
    }

    @Bean("shiroFilter")
    public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
        ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
        shiroFilter.setSecurityManager(securityManager);

        //oauth过滤
        Map<String, Filter> filters = new HashMap<>();
        filters.put("oauth2", new OAuth2Filter());
        shiroFilter.setFilters(filters);

        Map<String, String> filterMap = new LinkedHashMap<>();
        filterMap.put("/signature/**","anon");
        filterMap.put("/projectUpload/upload","anon");
        filterMap.put("/administrativematters/**", "anon");
        filterMap.put("/sys/role/wxupdate", "anon");
        filterMap.put("/bidd/**", "anon");
        filterMap.put("/sys/role/list", "anon");
        filterMap.put("/teacher/qualification/**", "anon");
        filterMap.put("/licence/**", "anon");
        filterMap.put("/wxApp/**", "anon");
        filterMap.put("/approvaltotal/**", "anon");
        filterMap.put("/statutelibrary/**", "anon");
        filterMap.put("/biddproject/**", "anon");
        filterMap.put("/institutionsmatters/**", "anon");
        filterMap.put("/matters/**", "anon");
        filterMap.put("/institutions/**", "anon");
        filterMap.put("/joints/**", "anon");
        filterMap.put("/webjars/**", "anon");
        filterMap.put("/druid/**", "anon");
        //--------------------接口
        filterMap.put("/app/**", "anon");
        filterMap.put("/projectfile/**", "anon");
        filterMap.put("/chat/**", "anon");
        filterMap.put("/xrebel/**", "anon");
        filterMap.put("/archives/**", "anon");
        filterMap.put("/websocketController/**", "anon");
        filterMap.put("/wxLogin/api/wx/getLuzhiUrl", "anon");
        filterMap.put("/carousel/image/**", "anon");
        filterMap.put("/exploration/cloud/**", "anon");
        filterMap.put("/wxLogin/**", "anon");
        filterMap.put("/sys/login", "anon");
        filterMap.put("/generator/tsysdictitem/getDictItemListForWx", "anon");
        filterMap.put("/appointment/matter/**", "anon");
        filterMap.put("/exploration/cloud/testFile", "anon");
        filterMap.put("/data/document/testFile", "anon");
        filterMap.put("/bank/**", "anon");
        filterMap.put("/audioVideo/**", "anon");
        filterMap.put("/bank/account/queryList", "anon");
        filterMap.put("/file/uploadFile", "anon");
        filterMap.put("/test/**", "anon");
        filterMap.put("/file/uploadFileByQh", "anon");
        filterMap.put("/file/deleteFile", "anon");
        filterMap.put("/assist/in/managing/**", "anon");
        filterMap.put("/to/do/immediately/**", "anon");
        filterMap.put("/uploadFile", "anon");
        filterMap.put("/room/store/noticePushTest", "anon");
        filterMap.put("/room/store/OpenAccountPushTest", "anon");
        filterMap.put("/room/store/callPushTest", "anon");
        filterMap.put("/room/store/delete", "anon");
        filterMap.put("/room/store/save", "anon");
        filterMap.put("/room/store/answerCall", "anon");
        filterMap.put("/room/store/getArea", "anon");
        filterMap.put("/data/document/testFile", "anon");
        filterMap.put("/auxiliary/approval/save", "anon");
        filterMap.put("/user/bank/pushBankTest", "anon");


        filterMap.put("/data/document/save", "anon");

        //--------------------接口
        filterMap.put("/sys/loginWeb", "anon");
        filterMap.put("/sys/user/checkUserName", "anon");
        filterMap.put("/sys/user/findByMobile", "anon");
        filterMap.put("/swagger/**", "anon");
        filterMap.put("/v2/api-docs", "anon");
        filterMap.put("/swagger-ui.html", "anon");
        filterMap.put("/swagger-resources/**", "anon");
        filterMap.put("/captcha.jpg", "anon");
        filterMap.put("/aaa.txt", "anon");
        filterMap.put("/loginSocket/**", "anon");
        filterMap.put("/audio/video/collect/**", "anon");
        filterMap.put("/data/document/updateType", "anon");
        filterMap.put("/project/list", "anon");
        filterMap.put("/project/save", "anon");
        filterMap.put("/project/get", "anon");
        filterMap.put("/process/**", "anon");
        filterMap.put("/processitem/**", "anon");
        filterMap.put("/processitem/getProcess/**", "anon");
        filterMap.put("/processitem/getProcessItem", "anon");
        filterMap.put("/projectUpload/uploadFile", "anon");
        filterMap.put("/image/get", "anon");
        filterMap.put("/imserver", "anon");
        filterMap.put("/projectschedule/list", "anon");
        filterMap.put("/projectschedule/nav", "anon");
        filterMap.put("/project/**", "anon");
        filterMap.put("/project/info/**", "anon");
        filterMap.put("/project/getProcess/**", "anon");
        filterMap.put("/projectUpload/uploadFileByUser", "anon");
        filterMap.put("/project/getCompanyProject", "anon");
        filterMap.put("/processitem/getItemFile", "anon");
        filterMap.put("/category/list", "anon");
        filterMap.put("/project/getProjectByName", "anon");
        filterMap.put("/category/companyList", "anon");
        filterMap.put("/enterprise/save", "anon");
        filterMap.put("/dictionary/get", "anon");
        filterMap.put("/**", "oauth2");
        shiroFilter.setFilterChainDefinitionMap(filterMap);

        return shiroFilter;
    }

    @Bean("lifecycleBeanPostProcessor")
    public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
        return new LifecycleBeanPostProcessor();
    }

    @Bean
    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
        AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
        advisor.setSecurityManager(securityManager);
        return advisor;
    }

}
